package cn.intotw.pp.server.core;

import cn.intotw.pp.decode.MessageDecoder;
import cn.intotw.pp.decode.PPProtocolDecoder;
import cn.intotw.pp.encode.MessageEncoder;
import cn.intotw.pp.encode.PPProtocolEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author Chenxiang
 * @Description: channel初始化
 * @create 2018/8/20 15:50
 */
@Component
@Scope("prototype")
public class PPServerChannelInitializer extends ChannelInitializer<NioSocketChannel> {

    protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception {
        ChannelPipeline p=nioSocketChannel.pipeline();
        p.addLast()
                .addLast(new PPProtocolEncoder())
                .addLast(new MessageEncoder())
                .addLast(new PPProtocolDecoder(2048))
                .addLast(new MessageDecoder())
                .addLast(new PPServerHandler());
    }
}